package com.example.liyuehui.dsldemo;

import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.internal.reflect.Instantiator;
import org.gradle.invocation.DefaultGradle;

/**
 * Created by LiYueHui on 2017/11/19.
 */

public class DslDemoPlugin implements Plugin<Project> {
	@Override
	public void apply(Project project) {
		Instantiator instantiator = ((DefaultGradle) project.getGradle()).getServices().get(
				Instantiator.class);
		NamedDomainObjectContainer<SmallExtension> smallExtensionsContainer = project.container(
				SmallExtension.class, new SmallExtensionFactory(instantiator));

		//create方法的第三个参数是MyExtension的构造参数
		MyExtension mMyExtension = project.getExtensions().create("myExtension", MyExtension.class,
				new Object[]{instantiator, smallExtensionsContainer});
		DumpTask task = project.getTasks().create("dump", DumpTask.class);
		task.setExtension(mMyExtension);
		task.setGroup("loc");
	}
}
